﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ManagerMachine
{
    public class AllocationPort
    {
        int min;
        int max;
        List<int> PortCreated;
        List<int> PortFree;
        Random ran;
        public AllocationPort(int min_port,int max_port)
        {
            this.min = min_port;
            this.max = max_port;
            PortCreated = new List<int>();
            PortFree = new List<int>();
            ran = new Random();
            for (int i = min_port; i <= max_port;i++ )
            {
                PortFree.Add(i);
            }
            
        }
        public int GetNewPort()
        {
            int index = ran.Next(0, PortFree.Count);
            int newport = PortFree[index];
            PortCreated.Add(newport);
            PortFree.Remove(newport);
            return newport;
        }
        public void ClosePort(int port)
        {
            PortCreated.Remove(port);
            PortFree.Add(port);
        }
    }
}
